package NC34_求路径;


public class Solution {
    /**
     *
     * @param m int整型
     * @param n int整型
     * @return int整型
     */
    public int uniquePaths (int m, int n) {
        // write code here
        int[][] dp = new int[m][n];

        for (int i = 0; i < m; i++){
            for (int j = 0; j < n; j++){
                // 当 i = 0 时，dp[0][j] = dp[0][j - 1]
                if (i == 0) {
                    dp[i][j] = 1;
                    continue;
                }
                // 当 j = 0 时，dp[i][o] = dp[i - 1][0]
                if (j == 0){
                    dp[i][j] = 1;
                    continue;
                }

                // 当 i > 1 & j > 1 时，dp[i][j] = dp[i][j - 1] + dp[i - 1][j]
                dp[i][j] = dp[i][j - 1] + dp[i - 1][j];
            }
        }
        return dp[m - 1][n - 1];
    }
}